package mobi.zeedev.flyingsaucer.common.WebQueryModule.impl;

import mobi.zeedev.flyingsaucer.common.WebQueryModule.interfaces.IResult;
import org.apache.http.client.CookieStore;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.cookie.Cookie;

import java.io.ByteArrayOutputStream;
import java.util.Collections;
import java.util.List;

public class Result implements IResult {

    Integer statusCode;
    List<Cookie> cookies;
    UrlEncodedFormEntity postParams;
    ByteArrayOutputStream content;

    public Result() {
//        cookies = new ArrayList<Cookie>();

    }


    @Override
    public Integer getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(Integer statusCode) {
        this.statusCode = statusCode;
    }

    @Override
    public ByteArrayOutputStream getContentAsByteArrayOutputStream() {
        return content;
    }


    public List<Cookie> getCookies() {
        return cookies;
    }

    public UrlEncodedFormEntity getPostParams() {
        return postParams;
    }


    public void setContent(ByteArrayOutputStream content) {
        this.content = content;
    }


    @Override
    public String getContent() {
        if (content != null) {
            return content.toString();
        } else {
            return null;
        }
    }

    public ByteArrayOutputStream getByteArrayOutputStream() {
        return content;
    }

    public void setCookies(CookieStore cookieStore) {
        List<Cookie> cookieListWeakCopy = Collections.unmodifiableList(cookieStore.getCookies());
        this.cookies = cookieListWeakCopy;
    }

    public void setCookies(List<Cookie> cookiesIn) {
        List<Cookie> cookieListWeakCopy = Collections.unmodifiableList(cookiesIn);
        this.cookies = cookieListWeakCopy;
    }

    public void setPostParams(UrlEncodedFormEntity postParams) {
        this.postParams = postParams;
    }

}
